* Uses the 1980 ANES Major Panel Study: https://electionstudies.org/data-center/1980-major-panel-study/

gen reagan_w1 = vmp0040
gen reagan_w2 = vmp2039
gen reagan_w3 = vmp3096

gen carter_w1 = vmp0039
gen carter_w2 = vmp2038
gen carter_w3 = vmp3095

gen reps_w1 = vmp0053
gen reps_w2 = vmp2053
gen reps_w3 = vmp3110

gen dems_w1 = vmp0052
gen dems_w2 = vmp2052
gen dems_w3 = vmp3109

foreach v of var reagan_w1-dems_w3 {
	replace `v' = . if `v'>100
	}


gen pid_w1 = vmp0191
replace pid_w1 = . if pid_w1 >6
replace pid_w1 = pid_w1 + 1
gen party = pid_w1
recode party (1=1) (2=1) (3=1) (5=0) (6=0) (7=0) (0=.) (4=.)

gen pid_w2 = vmp2212
replace pid_w2 = . if pid_w2 >6
replace pid_w2 = pid_w2 + 1

gen pid_w3 = vmp3212
replace pid_w3 = . if pid_w3 >6
replace pid_w3 = pid_w3 + 1


gen in_candidate_w1 = carter_w1 if party==1
replace in_candidate_w1 = reagan_w1 if party==0
gen out_candidate_w1 = reagan_w1 if party==1
replace out_candidate_w1 = carter_w1 if party==0

gen in_candidate_w2 = carter_w2 if party==1
replace in_candidate_w2 = reagan_w2 if party==0
gen out_candidate_w2 = reagan_w2 if party==1
replace out_candidate_w2 = carter_w2 if party==0

gen in_candidate_w3 = carter_w3 if party==1
replace in_candidate_w3 = reagan_w3 if party==0
gen out_candidate_w3 = reagan_w3 if party==1
replace out_candidate_w3 = carter_w3 if party==0

gen candidate_affective_w1 = (in_candidate_w1 - out_candidate_w1)
gen candidate_affective_w2 = (in_candidate_w2 - out_candidate_w2)
gen candidate_affective_w3 = (in_candidate_w3 - out_candidate_w3)


gen in_party_w1 = dems_w1 if party==1
replace in_party_w1 = reps_w1 if party==0
gen out_party_w1 = reps_w1 if party==1
replace out_party_w1 = dems_w1 if party==0

gen in_party_w2 = dems_w2 if party==1
replace in_party_w2 = reps_w2 if party==0
gen out_party_w2 = reps_w2 if party==1
replace out_party_w2 = dems_w2 if party==0

gen in_party_w3 = dems_w3 if party==1
replace in_party_w3 = reps_w3 if party==0
gen out_party_w3 = reps_w3 if party==1
replace out_party_w3 = dems_w3 if party==0

gen partisan_affective_w1 = (in_party_w1 - out_party_w1)
gen partisan_affective_w2 = (in_party_w2 - out_party_w2)
gen partisan_affective_w3 = (in_party_w3 - out_party_w3)



* Control variables
gen interest_w1 = vmp0005
replace interest_w1 = . if interest_w1>5
recode interest_w1 (5=1) (3=2) (1=3)
gen interest_w2 = vmp2001
replace interest_w2 = . if interest_w2>5
recode interest_w2 (5=1) (3=2) (1=3)
gen interest_w3 = vmp3001
replace interest_w3 = . if interest_w3>5
recode interest_w3 (5=1) (3=2) (1=3)


gen cares = vmp0007
replace cares = . if cares>3
recode cares (3=0)




gen pidi_w1 = abs(pid_w1-4)+1 
gen pidi_w2 = abs(pid_w2-4)+1 
gen pidi_w3 = abs(pid_w3-4)+1 



gen age = vmp0325

gen educ = vmp0334
replace educ = . if educ>10

gen allpanels = 1
replace allpanels = . if partisan_affective_w1==.
replace allpanels = . if partisan_affective_w2==.
replace allpanels = . if partisan_affective_w3==.
replace allpanels = . if candidate_affective_w1==.
replace allpanels = . if candidate_affective_w2==.
replace allpanels = . if candidate_affective_w3==.

ttest partisan_affective_w2= partisan_affective_w3

ttest candidate_affective_w2= candidate_affective_w3

